<!--纯文本部分-->
<script>
import {defineComponent} from 'vue'
import {replaceResource} from "@/assets/js/routerUtils";
import {emotes} from "@/assets/js/Emotes";

const pattern = /\[s:.+?:.+?]/g

export default defineComponent({
  name: "NgaText",
  props: {
    text: {type: String},
  },
  setup(props) {
    const replaceEmote = (text) => {
      const array = []
      let matcher;
      while (matcher = pattern.exec(text)) {
        array.push(matcher[0])
      }
      array.forEach(e => {
        if (emotes.hasOwnProperty(e)) {
          const emote = emotes[e]
          text = text.replace(e, `<img src="${replaceResource(emote.url)}" alt=""/>`)
        }
      })
      return text
    }

    return () => <span v-html={replaceEmote(props.text)}></span>
  },
  methods: {}
})
</script>

<template>

</template>

<style scoped>

</style>